#!/bin/sh
# clean up history and useless stuffs from pmwiki files (agent, diff, rev etc.)
# will clean the .pageindex as well.
# After you run the script, copy the content of "cleaned" back into the current folder.
# for ex: mv -f cleaned/* ./ && rm -fr cleaned
# Beware: in some (rare) case the text may be duplicated, so you'll have to correct it by hand.

cd wiki.d

if [ ! -d cleaned ]; then 
	mkdir cleaned
fi

for pmfile in Main.* Help.* Site.* PmWiki*.* Tags.* Blog.* Workshop.*  # Category.*
do
	cat $pmfile | grep "^version=" > cleaned/$pmfile
	cat $pmfile | grep "^author=" >> cleaned/$pmfile
	cat $pmfile | grep "^charset=" >> cleaned/$pmfile
	cat $pmfile | grep "^csum=" >> cleaned/$pmfile
	cat $pmfile | grep "^ctime=" >> cleaned/$pmfile
	cat $pmfile | grep "^name=" >> cleaned/$pmfile
	cat $pmfile | grep "^title=" >> cleaned/$pmfile
	cat $pmfile | grep "^description=" >> cleaned/$pmfile
	cat $pmfile | grep "^passwdattr=" >> cleaned/$pmfile
	cat $pmfile | grep "^passwdedit=" >> cleaned/$pmfile
	cat $pmfile | grep "^passwdread=" >> cleaned/$pmfile
	cat $pmfile | grep "^targets=" >> cleaned/$pmfile
	cat $pmfile | grep "^text=" >> cleaned/$pmfile
	echo "" >> cleaned/$pmfile
done

echo "" > .pageindex

echo "We propose to write the content of the cleaned folder back into the current folder. IT MAY NOT BE SAFE, but most of the time it should be ok. Will you dare it? (y/N)"
		read choice
			case $choice in
					"y"|"Y"|"yes")
						mv -f cleaned/* ./ 
						rm -fr cleaned
						echo "done"
						;;
					"n"|"N"|"no"|"NO"|"non"|*)
						echo "Nothing was changed. You can compare and copy the files yourself."
						;;
			esac


